package com.lc.YYGH.user.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lc.YYGH.cmnclient.cmnclient.DictFeignClient;
import com.lc.YYGH.enums.DictEnum;
import com.lc.YYGH.model.user.Patient;
import com.lc.YYGH.user.mapper.PatientMapper;
import com.lc.YYGH.user.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class PatientServiceImpl extends ServiceImpl<PatientMapper, Patient> implements PatientService
{
    @Autowired
    private DictFeignClient dictFeignClient;
    @Override
    public List<Patient> findAllByUserId(Long userId) {
        QueryWrapper<Patient> wrapper=new QueryWrapper<>();
        wrapper.eq("user_id",userId);
        List<Patient> patients=baseMapper.selectList(wrapper);
        for(Patient patient:patients)
        {
            this.packPatient(patient);

        }

        return patients;
    }

    @Override
    public Patient getPatientById(Long id) {
        Patient patient=this.packPatient(this.getById(id));
        return patient;
    }
    private Patient packPatient(Patient patient)
    {
        String contactsCertificatesTypeString=dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(),patient.getContactsCertificatesType());
       String certificatesTypeString=dictFeignClient.getName(DictEnum.CERTIFICATES_TYPE.getDictCode(),patient.getCertificatesType());
       String provinceString=dictFeignClient.getName(patient.getProvinceCode());
       String cityString=dictFeignClient.getName(patient.getCityCode());
       String districtString=dictFeignClient.getName(patient.getDistrictCode());
       patient.getParam().put("certificatesTypeString",certificatesTypeString);
       patient.getParam().put("contactsCertificatesTypeString",contactsCertificatesTypeString);
       patient.getParam().put("provinceString",provinceString);
       patient.getParam().put("cityString",cityString);
       patient.getParam().put("districtString",districtString);
       patient.getParam().put("fullAddress",provinceString+cityString+districtString+patient.getAddress());
       return patient;
    }
}
